Imports Microsoft.VisualBasic

Public Class ProductManager
    Public Function GetMPRange(ByVal mp As String) As List(Of String)
        Dim result As New List(Of String)

        Select Case mp
            Case "AllPLV"
                result.AddRange(New String() {"N1", "B1", "R1", "B2"})
            Case "AllFG"
                result.AddRange(New String() {"N1", "R1"})
            Case Else
                result.AddRange(New String() {mp})
        End Select

        Return result
    End Function

    Public Function NewDummyCode(ByVal signature As String) As String
        Dim dat As New clsData
        Dim sql As New StringBuilder
        Dim params As New Dictionary(Of String, Object)

        sql.AppendFormat("SELECT MAX(CAST(SUBSTRING(SapCode,6,3) AS INT)) FROM ProductData ")
        sql.AppendFormat("WHERE 1=1 ")
        'sql.AppendFormat("AND LEFT(ProdHierarchy,2) = @Signature ")
        sql.AppendFormat("AND LEFT(SapCode,5) = @CodePrefix ")

        Dim prefix As String = String.Format("B{0}{1}", DateTime.Now.Year - 2000, signature)

        params.Add("CodePrefix", prefix)
        params.Add("Signature", signature)

        Dim curr As Object = dat.GetSingleData(sql.ToString, params)
        Dim idfmt As String = prefix & "{0:000}"

        If curr Is DBNull.Value Then
            Return String.Format(idfmt, 1)
        Else
            Return String.Format(idfmt, curr + 1)
        End If
    End Function
End Class
